package com.lagou.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Restful⻛格
 */
@Controller
@RequestMapping("demo")
public class RestfullController {

    @RequestMapping(value = "/handle/{id}", method = {RequestMethod.GET})
    public ModelAndView handleGet(@PathVariable("id") Integer id) {
        Date date = new Date();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("date", date  + " id ==>>" + id);
        modelAndView.setViewName("success");
        return modelAndView;
    }

    @RequestMapping(value = "/handle", method = {RequestMethod.POST})
    public ModelAndView handlePost(String username) {
        Date date = new Date();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("date",date  + " username ==>>" + username);
        modelAndView.setViewName("success");
        return modelAndView;
    }

    @RequestMapping(value = "/handle/{id}/{name}", method = {RequestMethod.PUT})
    public ModelAndView handlePut(@PathVariable("id") Integer id,@PathVariable("name") String username) {
        Date date = new Date();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("date",date  + " id ==>>" + id  + " username ==>>" + username);
        modelAndView.setViewName("success");
        return modelAndView;
    }

    @RequestMapping(value = "/handle/{id}", method = {RequestMethod.DELETE})
    public ModelAndView handleDelete(@PathVariable("id") Integer id) {
        Date date = new Date();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("date", date  + " id ==>>" + id);
        modelAndView.setViewName("success");
        return modelAndView;
    }
}
